package com.yantong.controller.api;

import com.yantong.annotation.Auth;
import com.yantong.controller.BaseController;
import com.yantong.pojo.Member;
import com.yantong.result.ResultVo;
import com.yantong.service.MemberService;
import com.yantong.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: juzi
 * @date: 2021/10/25
 * @time: 16:12
 */
@ApiIgnore
@Controller
@RequestMapping("/wxapi/commander")
public class ApiCommanderController extends BaseController {

    @Autowired
    private MemberService memberService;

    /**
     * 门店订单统计
     */
    @RequestMapping("/order/count")
    @ResponseBody
    @Auth(arg = 0)
    public ResultVo getCommanderOrderCount(Long memberId, Long start, Long end) {
        Date startDate = new Date(start);
        Date endDate = new Date(end);
        List<Map<String, Object>> orderCounts = memberService.getCommanderProfitInfo(memberId, startDate, endDate);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", orderCounts);
        return resultVo;
    }

    /**
     * 门店预期收益
     */
    @RequestMapping("/income/expect")
    @ResponseBody
    @Auth(arg = 0)
    public ResultVo getCommanderExpectIncome(Long memberId) {
        double income = memberService.getTodayExpectIncome(memberId);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", income);
        return resultVo;
    }

    /**
     * 合作门店
     */
    @RequestMapping("/team")
    @ResponseBody
    @Auth(arg = 0)
    public ResultVo getTeams(Long memberId, int offset, int limit, String queryItem) {
        PageUtils<Member> teams = memberService.listTeamCommanders(memberId, queryItem, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", teams);
        return resultVo;
    }

}
